﻿//
//  Monkey Manager
//  Copyright (C) 2010 Victor Tereschenko (aka sibvic)
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//     
// ========================================================================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ManagerDB
{
    public enum WatchStatus
    {
        Unwatched,
        Watched,
        PartlyWatched,
        All,
    }

    public enum SortMode
    {
        NoSort,
        Ascending,
        Descending,
        Random,
    }

    public enum SortColumn
    {
        RowId,
        Name,
        Date
    }

    public enum FileStatus
    {
        Deleted,
        Present,
        All
    }

    public delegate void FilterChanged();

    public class Filter
    {
        public Filter Clone()
        {
            Filter clone = new Filter();
            clone.mWatchStatus = mWatchStatus;
            clone.mTags = mTags;
            clone.mSortColumn = mSortColumn;
            clone.mSortMode = mSortMode;
            clone.Limit = Limit;
            clone.Offset = Offset;
            clone.mText = mText;
            clone.mFileStatus = mFileStatus;
            return clone;
        }

        private WatchStatus mWatchStatus = WatchStatus.All;
        public WatchStatus WatchStatus
        {
            get { return mWatchStatus; }
            set
            {
                bool changed = mWatchStatus != value;
                mWatchStatus = value;
                if (changed && OnFilterChanged != null)
                    OnFilterChanged();
            }
        }

        private string mTags;
        public string Tags
        {
            get { return mTags; }
            set
            {
                bool changed = mTags != value;
                mTags = value;
                if (changed && OnFilterChanged != null)
                    OnFilterChanged();
            }
        }

        private SortColumn mSortColumn = SortColumn.RowId;
        public SortColumn SortColumn
        {
            get { return mSortColumn; }
            set
            {
                bool changed = mSortColumn != value;
                mSortColumn = value;
                if (changed && OnFilterChanged != null)
                    OnFilterChanged();
            }
        }

        private SortMode mSortMode = SortMode.Descending;
        public SortMode SortMode
        {
            get { return mSortMode; }
            set
            {
                bool changed = mSortMode != value;
                mSortMode = value;
                if (changed && OnFilterChanged != null)
                    OnFilterChanged();
            }
        }

        public int Limit = 100;
        public int Offset = 0;
        public event FilterChanged OnFilterChanged;
        private string mText;
        public string Text
        {
            get { return mText; }
            set
            {
                bool changed = mText != value;
                mText = value;
                if (changed && OnFilterChanged != null)
                    OnFilterChanged();
            }
        }
        public string TTH;

        private FileStatus mFileStatus = FileStatus.All;
        public FileStatus FileStatus
        {
            get { return mFileStatus; }
            set
            {
                bool changed = mFileStatus != value;
                mFileStatus = value;
                if (changed && OnFilterChanged != null)
                    OnFilterChanged();
            }
        }
    }
}
